package com.clear.wechat.handler;

import com.clear.wechat.handler.enums.WechatMSGEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class SubscribeMsgHandler implements WechatMsgHandler {

    /**
     * 获取枚举类型
     *
     * @return 订阅
     */
    @Override
    public WechatMSGEnum getMsgType() {
        return WechatMSGEnum.SUBSCRIBE;
    }

    /**
     * 具体业务逻辑，根据枚举类型不同执行不同逻辑
     *
     * @return
     */
    @Override
    public String dealMsg(Map<String,String> messageMap) {
        log.info("触发用户关注事件");
        String fromUserName = messageMap.get("FromUserName");
        String toUserName = messageMap.get("ToUserName");
        String subscribeContent = "非常感谢您的关注！我是clear，一个自学Java两年半的程序员，欢迎关注我的频道。";
        String content = "<xml>\n" +
                "  <ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
                "  <FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
                "  <CreateTime>12345678</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA[" + subscribeContent + "]]></Content>\n" +
                "</xml>";
        return content;

    }
}
